home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / query / mquery / mprofile.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-05-24  |  11.1 KB  |  393 lines

  1. VERSION 2.00
  2. Begin Form fStoreQry 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Stored Query Manager"
  6.    ClientHeight    =   3960
  7.    ClientLeft      =   1290
  8.    ClientTop       =   2685
  9.    ClientWidth     =   4980
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    Height          =   4365
  13.    Left            =   1230
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   3960
  19.    ScaleWidth      =   4980
  20.    Top             =   2340
  21.    Width           =   5100
  22.    Begin OptionButton OpSQLUser 
  23.       BackColor       =   &H00C0C0C0&
  24.       Caption         =   "Public:"
  25.       Height          =   240
  26.       Index           =   1
  27.       Left            =   465
  28.       TabIndex        =   7
  29.       Top             =   2250
  30.       Width           =   885
  31.    End
  32.    Begin OptionButton OpSQLUser 
  33.       BackColor       =   &H00C0C0C0&
  34.       Caption         =   "Private:"
  35.       Height          =   240
  36.       Index           =   0
  37.       Left            =   465
  38.       TabIndex        =   13
  39.       Top             =   1950
  40.       Value           =   -1  'True
  41.       Width           =   915
  42.    End
  43.    Begin CommandButton DeleteBtn 
  44.       Cancel          =   -1  'True
  45.       Caption         =   "&Delete"
  46.       Height          =   375
  47.       Left            =   3735
  48.       TabIndex        =   12
  49.       Top             =   3060
  50.       Width           =   1035
  51.    End
  52.    Begin SSPanel msgpanel 
  53.       Align           =   2  'Align Bottom
  54.       BevelInner      =   1  'Inset
  55.       Height          =   420
  56.       Left            =   0
  57.       TabIndex        =   6
  58.       Top             =   3540
  59.       Width           =   4980
  60.    End
  61.    Begin ListBox cqueries 
  62.       BackColor       =   &H00C0C0C0&
  63.       ForeColor       =   &H00000000&
  64.       Height          =   1005
  65.       Left            =   570
  66.       Sorted          =   -1  'True
  67.       TabIndex        =   11
  68.       TabStop         =   0   'False
  69.       Top             =   390
  70.       Width           =   3855
  71.    End
  72.    Begin CommandButton BtnQuit 
  73.       Caption         =   "&Quit"
  74.       Height          =   375
  75.       Left            =   2520
  76.       TabIndex        =   5
  77.       Top             =   3060
  78.       Width           =   1035
  79.    End
  80.    Begin CommandButton BtnRead 
  81.       Caption         =   "&Load"
  82.       Height          =   375
  83.       Left            =   1305
  84.       TabIndex        =   4
  85.       Top             =   3060
  86.       Width           =   1035
  87.    End
  88.    Begin CommandButton BtnWrite 
  89.       Caption         =   "&Save"
  90.       Height          =   375
  91.       Left            =   120
  92.       TabIndex        =   3
  93.       Top             =   3060
  94.       Width           =   1035
  95.    End
  96.    Begin TextBox TxtKey 
  97.       BackColor       =   &H00C0C0C0&
  98.       Height          =   375
  99.       Left            =   1500
  100.       TabIndex        =   2
  101.       Top             =   2520
  102.       Width           =   2895
  103.    End
  104.    Begin TextBox TxtSection 
  105.       BackColor       =   &H00C0C0C0&
  106.       Height          =   375
  107.       Left            =   1500
  108.       TabIndex        =   1
  109.       TabStop         =   0   'False
  110.       Top             =   2040
  111.       Width           =   2895
  112.    End
  113.    Begin TextBox TxtINIFile 
  114.       BackColor       =   &H00C0C0C0&
  115.       Enabled         =   0   'False
  116.       Height          =   375
  117.       Left            =   1500
  118.       TabIndex        =   0
  119.       TabStop         =   0   'False
  120.       Top             =   1560
  121.       Width           =   2895
  122.    End
  123.    Begin Label lblQueries 
  124.       Alignment       =   2  'Center
  125.       AutoSize        =   -1  'True
  126.       BackColor       =   &H00C0C0C0&
  127.       Caption         =   "Select Query"
  128.       Height          =   195
  129.       Left            =   540
  130.       TabIndex        =   9
  131.       Top             =   210
  132.       Width           =   1125
  133.    End
  134.    Begin Label LblKey 
  135.       Alignment       =   1  'Right Justify
  136.       AutoSize        =   -1  'True
  137.       BackColor       =   &H00C0C0C0&
  138.       Caption         =   "Query Name:"
  139.       Height          =   195
  140.       Left            =   285
  141.       TabIndex        =   8
  142.       Top             =   2640
  143.       Width           =   1110
  144.    End
  145.    Begin Label LblINIFile 
  146.       Alignment       =   1  'Right Justify
  147.       AutoSize        =   -1  'True
  148.       BackColor       =   &H00C0C0C0&
  149.       Caption         =   "Storage:"
  150.       Height          =   195
  151.       Left            =   690
  152.       TabIndex        =   10
  153.       Top             =   1620
  154.       Width           =   735
  155.    End
  156. Dim FwriteFlag As Integer ' did I   write
  157. Dim Fdelstr As String
  158. Dim FSection As String
  159. Dim fDefaultuser As String
  160. Sub BtnQuit_Click ()
  161. ' written or quit
  162. If FwriteFlag Then ' stored query
  163. FwriteFlag = False
  164. End If
  165. gstDynaString = ""
  166. ' was this a stored query that was run
  167. If Not gStoredFlag Then     'not from storage
  168.     fQuery!RunSaveQryButton.Enabled = True
  169.     fQuery!RunQueryButton.Enabled = False
  170.         If gfFROMSQL Then  ' was a SQL Statement?
  171.             fQuery!RunQueryButton.Enabled = False
  172.         End If
  173.     fQuery!RunSaveQryButton.Enabled = True
  174. End If
  175. Unload Me
  176. End Sub
  177. Sub BtnRead_Click ()
  178.     If TxtINIFile.Text = "" Then
  179.         Beep
  180.         TxtINIFile.SetFocus
  181.         Exit Sub
  182.     End If
  183.     If TxtSection.Text = "" Then
  184.         Beep
  185.         TxtSection.SetFocus
  186.         Exit Sub
  187.     End If
  188.     If Txtkey.Text = "" Then
  189.         Beep
  190.         Txtkey.SetFocus
  191.         Exit Sub
  192.     End If
  193.     'Assign textbox contents to variables for API call.
  194.     '(API call won't take references to Textbox contents.)
  195.     Sectn$ = TxtSection.Text
  196.     Keyy$ = Txtkey.Text
  197.     DeeFalt$ = ""
  198.     FileNam$ = gWindowsDirectory + "\" + TxtINIFile.Text
  199.      gstDynaString = StringfromPrivINI(Sectn$, Keyy$, DeeFalt$, FileNam$)
  200.     If gstDynaString = "" Then
  201.         msgpanel.Caption = "Section, Key or File name not found."
  202.     Else
  203.          
  204.          
  205.           fQuery!RunSaveQryButton.Enabled = False
  206.           DeleteBtn.Enabled = True
  207.          Unload Me
  208.     End If
  209. End Sub
  210. Sub BtnWrite_Click ()
  211.      FwriteFlag = False
  212.      DeleteBtn.Enabled = False
  213.     If TxtSection.Text = "" Then
  214.         Beep
  215.         TxtSection.SetFocus
  216.         Exit Sub
  217.     End If
  218.     If Txtkey.Text = "" Then
  219.         Beep
  220.         Txtkey.SetFocus
  221.         Exit Sub
  222.     End If
  223.     ' clear out GstDynaString if it has carriage return and linefeeds
  224.     ' pasted or otherwise inserted
  225.     a% = 0
  226.     For y% = 1 To Len(gstDynaString) - 2
  227.     a% = InStr(y% + a%, gstDynaString, Chr(13) + Chr(10))
  228.             If a% Then
  229.                 gstDynaString = Left(gstDynaString, a% - 1) + " " + Mid(gstDynaString, a% + 2, Len(gstDynaString))
  230.             End If
  231.     Next y%
  232.     Sectn$ = TxtSection.Text
  233.     Keyy$ = Txtkey.Text
  234.     Valyue$ = gstDynaString
  235.     FileNam$ = gWindowsDirectory + "\" + TxtINIFile.Text
  236.     Result% = StringtoPrivINI(Sectn$, Keyy$, Valyue$, FileNam$)
  237.     If Result% = 0 Then
  238.          msgpanel.Caption = "QUERY NOT SAVED."
  239.     Else
  240.          msgpanel.Caption = "QUERY SAVED."
  241.          FwriteFlag = True
  242.     End If
  243.     gstDynaString = ""
  244. End Sub
  245. Sub cqueries_Click ()
  246. If gstDynaString = "" Then
  247. Txtkey.Text = cqueries.List(cqueries.ListIndex)
  248. BtnRead.Enabled = True
  249. DeleteBtn.Enabled = True
  250. msgpanel.Caption = "QUERY SELECTED ...LOAD OR DELETE OR QUIT."
  251. End If
  252. End Sub
  253. Sub cqueries_KeyPress (keyascii As Integer)
  254. keyascii = 0
  255. End Sub
  256. Sub DeleteBtn_Click ()
  257. Fdelstr = Txtkey.Text
  258. If MsgBox("Delete " & Fdelstr & " ?", MSGBOX_TYPE) = YES Then
  259. delquery
  260. Unload Me
  261. End If
  262. End Sub
  263. Sub delquery ()
  264. Dim f As String
  265. Dim h As String
  266. Dim a As Integer
  267. Dim b As Integer
  268. Dim filein As String
  269. Dim fileout As String
  270. On Error GoTo errorhere
  271. a = InStr(1, TxtINIFile.Text, ".")
  272. filein = gWindowsDirectory + "\" + TxtINIFile.Text
  273. fileout = gWindowsDirectory + "\" + Left(TxtINIFile, a) + "bak"
  274. h = FSection
  275. Open filein For Input As 1
  276. Open fileout For Output As 2
  277. h = Fdelstr
  278. a = 0
  279. Do Until a > 0
  280.     Line Input #1, f
  281.     a = InStr(1, f, FSection)
  282.     Print #2, f
  283. Do Until EOF(1)
  284.      Line Input #1, f
  285.      a = InStr(1, f, h)
  286.      b = InStr(1, f, "[")
  287.      If b = 1 Then ' found new section
  288.         Print #2, f
  289.         h = "XXXXXX"
  290.      Else
  291.          If a = 0 Then
  292.          Print #2, f
  293.          End If
  294.      End If
  295. closeem:
  296.         Close 1
  297.         Close 2
  298. Kill filein
  299. Name fileout As filein
  300. MsgBox Fdelstr & " Deleted", 48
  301. Exit Sub
  302. errorhere:
  303. MsgBox "Error " & Str(Err), 48
  304. Resume closeem
  305. End Sub
  306. Sub Form_Load ()
  307.     fStoreQry.Left = (Screen.Width - fStoreQry.Width) / 2
  308.     fStoreQry.Top = (Screen.Height - fStoreQry.Height) / 2
  309. '*******************************************************
  310. '*  FDefaultuser can be the user ID from a network     *
  311. '*  Then sections can be PUBLIC for all users and      *
  312. '*  Private for the individual.  This way someone      *
  313. '*  who has a particular query for the database        *
  314. '*  can share it with others.                          *
  315. '*******************************************************
  316.        
  317.        gWindowsDirectory = WinDir()
  318.        fDefaultuser = "SMYTHERE" ' from network ID if MU
  319.        gSQLUser = fDefaultuser
  320.        getsections
  321.         BtnWrite.Enabled = False
  322.         BtnRead.Enabled = False
  323.         DeleteBtn.Enabled = False
  324. If gstDynaString <> "" Then
  325. Txtkey.Text = ""
  326. BtnWrite.Enabled = True
  327. DeleteBtn.Enabled = False
  328. msgpanel.Caption = "Enter a Query Name then SAVE or QUIT"
  329. End If
  330. End Sub
  331. Sub getsections ()
  332. Dim a As Integer
  333. Dim b As Integer
  334. Dim f As String
  335. Dim filein As String
  336. FSection = gSQLUser
  337. TxtSection.Text = FSection
  338. TxtINIFile.Text = "STOREQRY.INI"
  339. filein = TxtINIFile.Text
  340. On Error GoTo nofile
  341. Open gWindowsDirectory + "\" + TxtINIFile.Text For Input As 1
  342.     Line Input #1, f
  343.     a = InStr(1, f, "[" + FSection + "]")
  344. Loop Until a > 0
  345. ' check to see why loop ended
  346. If a Then ' found the section
  347.     Do ' loop until no more keys
  348.             If EOF(1) Then
  349.                 Close 1
  350.                 Exit Sub
  351.             End If
  352.         Line Input #1, f  ' read next line
  353.         a = InStr(1, f, "=") ' if true then we have a key and value
  354.             If a = 0 Then
  355.                     Close 1
  356.                     Exit Sub
  357.             End If
  358.             
  359.                 b = InStr(1, f, "=")  ' true so parse it
  360.                 cqueries.AddItem Left(f, b - 1) 'add query name to combo box
  361.     Loop
  362. Else ' this database not here
  363. MsgBox gstDBname + " Not Found"
  364. Close 1
  365. Exit Sub
  366. End If
  367. getout:
  368. Close 1
  369. Exit Sub
  370. nofile:
  371. If Err = 62 Then
  372. Resume getout
  373. MsgBox "error = " + Str(Err)
  374. Resume getout
  375. End If
  376. End Sub
  377. Sub opSQLUser_Click (Index As Integer)
  378. SQLUserSelect (Index)
  379. cqueries.Clear
  380. getsections' Form_Load
  381. End Sub
  382. Sub SQLUserSelect (I As Integer)
  383. If I = 0 Then
  384.   gSQLUser = fDefaultuser
  385.   gSQLUser = "PUBLIC"
  386. End If
  387. End Sub
  388. Sub TxtKey_KeyPress (keyascii As Integer)
  389. If gstDynaString = "" Then
  390. keyascii = 0
  391. End If
  392. End Sub
  393.